package com.intelligentcar.springboot.controller;

import com.intelligentcar.springboot.bean.Driversalary;
import com.intelligentcar.springboot.bean.News;
import com.intelligentcar.springboot.bean.Partner;
import com.intelligentcar.springboot.service.AdvertisementService;
import com.intelligentcar.springboot.service.NewsService;
import com.intelligentcar.springboot.service.PartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PartnerController {

    @Autowired
    PartnerService partnerService;
//    @Autowired
//    AdvertisementService advertisementService;


    @RequestMapping("/LookPP")
    @ResponseBody   //加这个注释,直接给数据,跳过视图层
    public Map list(@RequestBody Partner partner) {
        Map map = new HashMap();
        if (partner.getInput().equals("") || partner.getInput() == "") {
            List<Partner> list = partnerService.LookL(partner);
            map.put("list", list);
            map.put("total", partnerService.selectpartner());
        }
        for (int i = partner.getInput().length(); --i >= 0; ) {
            int chr = partner.getInput().charAt(i);
            if (chr < 48 || chr > 57) {
                List<Partner> list = partnerService.LookL(partner);
                map.put("list", list);
                map.put("total", partnerService.selectpartner());
            } else {
//                driversalary.setTime(driversalary.getInput());
                System.out.println(partner.getInput());
                List<Partner> list = partnerService.LookT(partner.getInput());
                map.put("list", list);
                map.put("total", partnerService.selectpartner());
            }
        }
        return map;
    }

    //    供应商界面数据展示
    @RequestMapping("/Lookpartner")
    @ResponseBody   //加这个注释,直接给数据,跳过视图层
    public Map list() {
        List<Partner> list = partnerService.Lookpartner();
//        System.out.println("213");
//       System.out.println(newsService.selectNews());
        Map map = new HashMap();
        map.put("list", list);
        map.put("total", partnerService.selectpartner());
//        System.out.println(list.get(0).getNewsMessage());
//        System.out.println(list.get(0).getNewsUrl());
//        System.out.println("1111111110000000000000000000000000000000++11111111111111111111");
        return map;
    }

    //    供应商界面中的修改信息操作
    @RequestMapping("/updpartner")
    @ResponseBody //跳过视图解析器,直接返回数据
    public Map<String, Object> updatepartner(@RequestBody Partner partner) {

//        System.out.println((news.getId()+"2222222222222"));
//        System.out.println(news.getNewsMessage()+"000000000000000000000000");
//        System.out.println(goods.getGoodsnum());
//        System.out.println(goods.getType());
        Map<String, Object> map = new HashMap<>();
        map.put("code", partnerService.updatepartner(partner));
        return map;
    }

    //供应商界面中的删除信息操作
    @RequestMapping("/delpartner")//请求路径
    @ResponseBody //跳过视图解析器,直接返回数据
    public String deletepartner(long id) {
//        String id1 =intValue(id);;
        partnerService.deletepartner(id);
        System.out.println("id是:" + id);
        return "success";
    }

    //供应商界面中的新增信息操作
    @RequestMapping("/addpartner")
    @ResponseBody //跳过视图解析器,直接返回数据
    public Map<String, Object> addpartner(@RequestBody Partner partner) {
        Map<String, Object> map = new HashMap<>();
        int i = partnerService.addpartner(partner);
        if (i > 0) {
            System.out.println(partner.getPname() + "66666666");
//            List<Partner>  list =  partnerService.LookKK(partner);
//            System.out.println( list.get(0).getId() + "99999999999999");
//            int adid = partnerService.addADD((int) list.get(0).getId());
//            if (adid > 0 ){
            map.put("code", i);
//            }
        }
//        System.out.println((partner.getId() + "2222222222222"));
//        System.out.println(partner.getPaddress() + "000000000000000000000000");
////        System.out.println(goods.getGoodsnum());
////        System.out.println(goods.getType());
//        Map<String, Object> map = new HashMap<>();
//        map.put("code", partnerService.addpartner(partner));
        return map;
//}

    }
}
